{% macro pagination_widget(pagination, fragment='') %}
<ul class="pagination">
    {% if pagination.has_prev %}
        <li>
            <a href="{{ url_for_other_page(page=1) }}">首页</a>
        </li>
    {% endif %}
    <li {% if not pagination.has_prev %} class="disabled"{% endif %}>
        <a href="{% if pagination.has_prev %}{{ url_for_other_page(page=pagination.prev_num, **kwargs) }}{{ fragment }}{% else %}#{% endif %}">
            上一页
        </a>
    </li>
    {% for p in pagination.iter_pages() %}
        {% if p %}
            {% if p == pagination.page %}
            <li class="active">
                <a href="{{ url_for_other_page(page = p, **kwargs) }}{{ fragment }}">{{ p }}</a>
            </li>
            {% else %}
            <li>
                <a href="{{ url_for_other_page(page = p, **kwargs) }}{{ fragment }}">{{ p }}</a>
            </li>
            {% endif %}
        {% else %}
        <li class="disabled"><a href="#">&hellip;</a></li>
        {% endif %}
    {% endfor %}
    <li {% if not pagination.has_next %} class="disabled"{% endif %}>
        <a href="{% if pagination.has_next %}{{ url_for_other_page(page=pagination.next_num, **kwargs) }}{{ fragment }}{% else %}#{% endif %}">
            下一页
        </a>
    </li>
    {% if pagination.has_next %}
        <li>
            <a href="{{ url_for_other_page(page=pagination.pages) }}">尾页</a>
        </li>
    {% endif %}
</ul>
{% endmacro %}

{% macro pager_summary(pagination) %}
<div class="dataTables_info" id="example2_info" role="status" aria-live="polite">
    {% set begin_num=(pagination.prev_num * pagination.per_page + 1) %}
    {% set end_num=((pagination.next_num - 1) * pagination.per_page) %}

    {% if end_num > pagination.total %}
        {% set end_num=pagination.total %}
    {% endif %}

    当前显示第{{ begin_num }} - {{ end_num }}条记录，共{{ pagination.total }}条记录.
</div>
{% endmacro %}

{% macro pager_render(pagination, fragment='') %}
<div class="row">
    <div class="col-sm-12">
        {{ pager_summary(pagination) }}
    </div>
</div>
<div class="row">
    <div class="col-sm-12 text-right">
        {{ pagination_widget(pagination, fragment, **kwargs) }}
    </div>
</div>
{% endmacro %}}